<template>
  <div>
    <el-table :data="tableData" style="width: 100%" max-height="600px">
      <el-table-column type="expand">
        <template slot-scope="props">
          <ul class="export-second table-title">
            <li class="title">评分标准</li>
            <li>分值</li>
            <li>创建时间</li>
            <li class="cz">操作</li>
          </ul>
          <ul
            class="export-second"
            v-for="v in props.row.childList"
            :key="v.id"
          >
            <li class="title">{{ v.content }}</li>
            <li>{{ v.minScore }} ~ {{ v.maxScore }}</li>
            <li>{{ v.createTime }}</li>
            <li class="cz">
              <el-button-group>
                <el-button type="primary" size="mini" @click="handleEdit(v)"
                  >编辑</el-button
                >
                <el-button type="danger" size="mini" @click="handleDelete(v)"
                  >删除</el-button
                >
              </el-button-group>
            </li>
          </ul>
        </template>
      </el-table-column>
      <el-table-column prop="orderBy" label="排序" width="60">
      </el-table-column>
      <el-table-column prop="content" label="评分项">
        <template slot-scope="scope">
          <p class="sheng">{{ scope.row.content || '--' }}</p>
        </template>
      </el-table-column>
      <el-table-column prop="deptName" label="总分值" width="120">
        <template slot-scope="scope">
          <p>{{ totalScore(scope.row.childList) }}</p>
        </template>
      </el-table-column>
      <el-table-column prop="type" label="类型" width="180">
        <template slot-scope="scope">
          <p>{{ scope.row.type | auditType }}</p>
        </template>
      </el-table-column>
      <el-table-column prop="createTime" label="创建时间" width="180">
      </el-table-column>
      <el-table-column label="操作" width="260">
        <template slot-scope="{ row }">
          <el-button-group>
            <el-button type="primary" size="mini" @click="handleAdd(row)"
              >新增评分标准</el-button
            >
            <el-button type="primary" size="mini" @click="handleEdit(row)"
              >编辑</el-button
            >
            <el-button type="danger" size="mini" @click="handleDelete(row)"
              >删除</el-button
            >
          </el-button-group>
        </template>
      </el-table-column>
    </el-table>
    <!-- <Pagination
      v-show="parseInt(pageObj.count) > 0"
      :total="parseInt(pageObj.count)"
      @change="getList"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
    /> -->
  </div>
</template>
<script>
import {
  expertsScoreItemQuery,
  expertsScoreItemDelete,
} from '@/api/admin/audit/expertsScoreItem.js'
import Bus from '@/utils/bus.js'
export default {
  data() {
    return {
      listQuery: {
        scope: '',
        type: '',
        extFiled: '',
      },
      tableData: [],
      pageObj: {},
    }
  },
  props: ['flowData', 'extFiled'],
  computed: {
    schoolScoped() {
      return function (v) {
        if (v && v.sysDeptList) {
          return v.sysDeptList.map((v) => v.name).toString()
        } else {
          return '--'
        }
      }
    },
    totalScore() {
      return function (v) {
        return v.reduce((total, item) => total + parseInt(item.maxScore), 0)
      }
    },
  },
  mounted() {
    this.getList()
    Bus.$on('refreshFlowList', (v) => {
      if (v) {
        Object.assign(this.listQuery, v)
      }
      this.getList()
    })
  },
  beforeDestroy() {
    Bus.$off('refreshFlowList')
  },
  methods: {
    getList() {
      if (this.flowData) {
        this.listQuery.scope = this.flowData.scope
        this.listQuery.type = this.flowData.extFiled
      } else if (this.extFiled) {
        this.listQuery.scope = this.extFiled.deptId
        this.listQuery.type = this.extFiled.courseType
        this.listQuery.extFiled = this.extFiled.reviewId
      }

      expertsScoreItemQuery(this.listQuery).then((res) => {
        this.tableData = res.data.data
        this.pageObj = res.data
      })
    },
    //新增二级指标
    handleAdd(row) {
      Bus.$emit('showDialogFlowAdd', { row, type: 'add' })
    },
    //编辑
    handleEdit(row) {
      Bus.$emit('showDialogFlowAdd', { row, type: 'edit' })
    },
    //删除确认
    handleDelete(row) {
      this.$confirm('确定要删除吗?', '提示', {
        confirmButtonText: '删除',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          this.delete(row)
        })
        .catch(() => {})
    },
    //删除
    delete(row) {
      expertsScoreItemDelete(row.id).then((res) => {
        if (!res || res.data.code != 0) return
        this.getList()
        this.$message({
          message: '操作成功',
          type: 'success',
        })
      })
    },
  },
}
</script>
<style scoped lang="scss">
.export-second {
  padding-left: 50px;
  li {
    padding: 5px 10px;
    float: left;
    width: 20%;
    box-sizing: border-box;
    border-bottom: 1px solid #ebeef5;
  }
  .title {
    width: 45%;
  }
  .cz {
    width: 15%;
  }
}
.table-title {
  li {
    background-color: #f5f5f5;
  }
}
</style>